<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="订单号" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前房间" prop="premisesAddress">
        <el-input v-model="queryParams.premisesAddress" placeholder="请输入" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住客名称" prop="lesseeName">
        <el-input v-model="queryParams.lesseeName" placeholder="请输入" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源" prop="orderSource">
        <el-select v-model="queryParams.orderSource" placeholder="来源" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.order_source" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="入离时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        @change="dateRangeChange"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="orderState">
        <el-select v-model="queryParams.orderState" placeholder="" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.order_short_state" :key="dict.value" :label="dict.label"
                     :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!--        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新建</el-button>-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="roomList" @selection-change="handleSelectionChange" ref="table">

      <el-table-column label="订单编号" prop="orderId"/>
      <el-table-column label="当前房间" prop="premisesAddress" :show-overflow-tooltip="true"/>
      <el-table-column label="住客信息" prop="reservationName" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>{{ scope.row.orderLessee.lesseeName }}</div>
          <div>{{ scope.row.orderLessee.phone }}</div>
        </template>
      </el-table-column>
      <el-table-column label="来源" prop="houseType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_source" :value="scope.row.orderSource"/>
        </template>
      </el-table-column>
      <el-table-column label="入离日期" prop="roleSort">
        <template slot-scope="scope">
          <div>
            入：{{ scope.row.checkInTime | formatDate('YYYY-MM-DD') }}
          </div>
          <div>
            离：{{ scope.row.checkOutTime | formatDate('YYYY-MM-DD') }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="houseManagerName">

        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_short_state" :value="scope.row.orderState"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)">详情</el-button>
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">订房明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <detail v-model="detailVisible" :orderId="orderId"/>
    <price-detail v-model="pricelVisible" v-if="pricelVisible" :orderId="orderId"/>
  </div>
</template>

<script>
import {
  listOrder
} from '@/api/order/short'
import detail from './component/detail.vue'
import priceDetail from './component/priceDetail.vue'

export default {
  name: 'shortOrder',
  dicts: ['order_short_state', 'order_source'],
  components: {
    detail,
    priceDetail
  },
  data() {
    return {
      detailVisible: false,
      pricelVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      roomList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 当前选择
      current: '0',
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],

      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // roomNumber: undefined,
        // roleKey: undefined,
        // status: undefined,
        // orderState: undefined,
        // orderIds: undefined,
        // orderSource: undefined,

        orderId: undefined,
        premisesAddress: undefined,
        lesseeName: undefined,
        phone: undefined,
        orderSource: undefined,
        checkInTime: undefined,
        checkOutTime: undefined

      },
      countHouseList: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 表单校验
      rules: {
        roomNumber: [
          { required: true, message: '角色名称不能为空', trigger: 'blur' }
        ],
        roleKey: [
          { required: true, message: '权限字符不能为空', trigger: 'blur' }
        ],
        roleSort: [
          { required: true, message: '角色顺序不能为空', trigger: 'blur' }
        ]
      },
      detailDialogVisible: false,
      orderId: '',
      openChangeHouse: false,
      openEdit: false,
      orderInfo: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    dialogClose() {
      this.openChangeHouse = false
      this.openEdit = false
    },
    stateHandel(i) {
      let orderState = this.countHouseList[i].value
      this.queryParams.orderState = orderState
      this.handleQuery()
    },
    diaclose() {
      this.open = false
      this.getList()
    },
    /** 查询房间列表 */
    getList() {
      this.loading = true
      listOrder(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.roomList = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId)
      this.single = selection.length != 1
      this.multiple = !selection.length
      this.queryParams.orderIds = this.ids
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.orderId = ''
      this.open = true
    },
    // 详情操作
    handleDetail(row) {
      this.orderId = row.orderId
      this.detailVisible = true
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.orderId = row.orderId
      this.pricelVisible = true
    },
    //换房操作
    handleChangeHouse(row) {
      this.orderInfo = row
      this.openChangeHouse = true
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'enterprise/order/order/export',
        {
          ...this.queryParams
        },
        `订单_${new Date().getTime()}.xlsx`
      )
    },
    //请空选择项
    clearSelect() {
      this.$refs.table.clearSelection()
    },
    //入离时间改变
    dateRangeChange(e) {
      this.queryParams['checkInTime'] = e ? e[0] : undefined
      this.queryParams['checkOutTime'] = e ? e[1] : undefined

    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  font-weight: 500;
  color: #666;
}

.total {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}

.left-border {
  border-left: 1px solid #999;
}

.right-border {
  border-right: 1px solid #999;
}

.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;

  span {
    color: #565c5f;
  }

  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
